package com.appcenter.monitor.controller;

import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;
import com.appcenter.monitor.input.logs.GetLogsInput;
import com.appcenter.monitor.input.operats.GetOperatsInput;
import com.appcenter.monitor.input.operats.PageLoadInput;
import com.appcenter.monitor.service.OperatsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/services/jzmonitorcenter/Operat")
@Api("操作日志API")
public class OperatsController {
    @Autowired
    OperatsService operatsService;

    @ApiOperation(value = "查询操作日志信息", notes = "查询操作日志信息",produces = "application/json")
    @PostMapping("/getOperats")
    public ResponseEntity<JsonResult> GetLogs(@RequestBody GetOperatsInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(operatsService.GetOperats(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }

        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "加载系统日志", notes = "加载系统日志",produces = "application/json")
    @PostMapping("/pageLoad")
    public ResponseEntity<JsonResult> PageLoad(@RequestBody PageLoadInput input) throws Exception {
        JsonResult r = new JsonResult();
        try {
            r.setResult(operatsService.PageLoad(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
}
